<template>
  <div>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- input输入框 -->
      <el-form :inline="true">
        <el-form-item>
          <el-input class="search" v-model="search" placeholder="请输入内容" />
          <el-button :icon="Search" @click="query"></el-button>
        </el-form-item>
      </el-form>
      <!-- 表格 -->
      <el-table border stripe :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" width="80"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="200"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status == 0" type="danger">未付款</el-tag>
            <el-tag v-else type="success">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间"></el-table-column>
        <el-table-column prop="address" label="操作">
          <el-button type="primary" :icon="EditPen" size="small" @click="ordersModify = true"></el-button>
          <el-button type="success" :icon="Location" size="small" @click="dialogOrders = true"></el-button>
        </el-table-column>
      </el-table>
      <!-- 分页  v-model:current-page当前页数  v-model:page-size每页显示条目个数
        small是否使用小型分页样式  disabled是否禁用分页 -->
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[1, 5, 10, 15]"
        small
        :disabled="disabled"
        :background="background"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
      <!-- 订单信息 -->
      <el-dialog title="物流进度" v-model="dialogOrders" width="50%">
        <el-timeline>
          <el-timeline-item v-for="(activity, index) in datalist" :key="index" :timestamp="activity.time">
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
  <el-dialog title="修改地址" v-model="ordersModify" width="50%">
    <el-form>
      <el-form-item label="省市区/县" label-width="140px">
        <el-cascader v-model="value" :options="options" :props="props" />
      </el-form-item>
    </el-form>
    <el-button @click="ordersModify = false">取 消</el-button>
    <el-button type="primary" @click="ordersModify = false">确 定</el-button>
  </el-dialog>
</template>

<script setup lang="ts">
// 字体 图标
import { Search, EditPen, Location } from '@element-plus/icons-vue'
import request from '@/util/request'
import { ElMessage } from 'element-plus'
import { onMounted, ref } from 'vue'
// 地区
import option from "@/assets/city_data2017_element.js"
// 搜索框
const search = ref('')
// 表格数据
const tableData = ref([])
// 分页
// 总条数
const total = ref(100)
// 当前页
const currentPage = ref(1)
// const currentPage = 1
// 每页查询条数
let pageSize = 5
// 是否禁用分页
const disabled = ref(false)
// 是否为分页按钮添加背景色
const background = ref(false)
// page-size 改变时触发
const handleSizeChange = (size: number) => {
  pageSize = size
  getOrdersList()
  console.log('handleSizeChange')
}
// current-page 改变时触发
const handleCurrentChange = (current: number) => {
  currentPage.value = current
  getOrdersList()
  console.log('handleCurrentChange')
}
// 对话框是否显示
const ordersModify = ref(false)
// 对话框是否显示
const dialogOrders = ref(false)
const datalist = [
  {
    time: '2018-05-10 09:39:00',
    ftime: '2018-05-10 09:39:00',
    context: '已签收,感谢使用顺丰,期待再次为您服务',
    location: '',
  },
  {
    time: '2018-05-10 08:23:00',
    ftime: '2018-05-10 08:23:00',
    context: '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
    location: '',
  },
  {
    time: '2018-05-10 07:32:00',
    ftime: '2018-05-10 07:32:00',
    context: '快件到达 [北京海淀育新小区营业点]',
    location: '',
  },
  {
    time: '2018-05-10 02:03:00',
    ftime: '2018-05-10 02:03:00',
    context: '快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]',
    location: '',
  },
  {
    time: '2018-05-09 23:05:00',
    ftime: '2018-05-09 23:05:00',
    context: '快件到达 [北京顺义集散中心]',
    location: '',
  },
  {
    time: '2018-05-09 21:21:00',
    ftime: '2018-05-09 21:21:00',
    context: '快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]',
    location: '',
  },
  {
    time: '2018-05-09 13:07:00',
    ftime: '2018-05-09 13:07:00',
    context: '顺丰速运 已收取快件',
    location: '',
  },
  {
    time: '2018-05-09 12:25:03',
    ftime: '2018-05-09 12:25:03',
    context: '卖家发货',
    location: '',
  },
  {
    time: '2018-05-09 12:22:24',
    ftime: '2018-05-09 12:22:24',
    context: '您的订单将由HLA（北京海淀区清河中街店）门店安排发货。',
    location: '',
  },
  {
    time: '2018-05-08 21:36:04',
    ftime: '2018-05-08 21:36:04',
    context: '商品已经下单',
    location: '',
  },
]
const query = () => {
  // 每次搜索,页数从1开始
  currentPage.value = 1
  getOrdersList()
  console.log(123456)
}
onMounted(() => {
  getOrdersList()
})
const getOrdersList = async () => {
  const { data, meta } = await request({
    url: `/orders?query=${search.value}&pagenum=${currentPage.value}&pagesize=${pageSize}`,
    method: 'GET',
    // params: {
    //   query: search.value,
    //   pagenum: currentPage,
    //   pagesize: pageSize,
    // },
  })
  if (meta.status !== 200) {
    return ElMessage.error('获取订单列表失败')
  }
  tableData.value = data.goods
  total.value = data.total
  // console.log(data, '--------')
}
// 修改地址数据
const value = ref([])
const options = option
const props = {
  expandTrigger: 'hover' as const,
}
</script>

<style scoped>
.search {
  width: 540px;
}
</style>
